package common.model
{
	import common.util.CodeModelUtil;
	
	import ui.maps.PointModel;

	[Bindable]
	public class StaffGpsModel
	{
		public static var OFF_SITE:String="OFF_SITE";
		public static var OFF_SITE_NAME:String = "脱岗";
		public static var ON_WORK_AREA:String="ON_WORK_AREA";
		public static var ON_WORK_AREA_NAME:String = "工作中";
		public static var ON_PASSAGE:String="ON_PASSAGE";
		public static var ON_PASSAGE_NAME:String = "在途中";
		
		public var staffId:String;
		public var staffNo:String;
		public var staffMobileNumber:String;
		public var staffName:String;
		public var staffHomeAddress:String;
		public var depName:String;
		public var staffState:String;
		public var staffStateName:String;
		public var cmdState:String;
		public var cmdStateName:String;
		
		public var reportTime:String;
		public var speed:String;
		public var logit:Number;
		public var lat:Number;
		public var logitOffset:Number;
		public var latOffset:Number;
		public var locDesc:String;
		public var angle:String;
		
		public var direction:String;//中文方向
		public var phoneState:String;//手机状态
		
		public var checked:String='0';//是否被勾选
		
		
		public function StaffGpsModel(staff:WqStaffInfo=null) {
			if(staff != null){
				staffId = staff.id;
				staffNo = staff.staffNo;
				staffName = staff.cnName;
				staffMobileNumber = staff.mobileNumber;
				staffHomeAddress = staff.homeAddress;
				depName = CodeModelUtil.getWqDepInfoNameByStaffId(staffId);
			}
		}
		
		public function setDcGpsReal(gps:DcGpsReal):void{
			if(staffId == null){
				var staff:WqStaffInfo = CodeModelUtil.getWqStaffInfoByStaffId(gps.tmnAlias);
				if(staff == null){
					return;
				}
				staffId = staff.id;
				staffNo = staff.staffNo;
				staffName = staff.cnName;
				staffMobileNumber = staff.mobileNumber;
				staffHomeAddress = staff.homeAddress;
				depName = CodeModelUtil.getWqDepInfoNameByStaffId(staffId);
			}
			
			this.reportTime = gps.reportTime;
			this.speed = gps.speed;
			this.logit = gps.logit;
			this.lat = gps.lat;
			this.logitOffset = gps.logitOffset;
			this.latOffset = gps.latOffset;
			this.locDesc = gps.reportTime ? ((gps.isValidGps==false ? '[无效定位] ' : '')+(gps.locDesc||'')) : gps.locDesc;
			this.angle = gps.angle;
			this.staffState = gps.state;
			setStateName();
			
			this.cmdState = gps.cmdState;
			this.cmdStateName = CmdModel.getCmdStateNameByStateCode(cmdState);
			
			this.phoneState = gps.phoneState;
		}
		
		public function setWqPlanLocateDetail(planLocate:WqPlanLocateDetail):void{
			if(staffId == null){
				var staff:WqStaffInfo = CodeModelUtil.getWqStaffInfoByStaffId(planLocate.staffId);
				if(staff == null){
					return;
				}
				staffId = staff.id;
				staffNo = staff.staffNo;
				staffName = staff.cnName;
				staffMobileNumber = staff.mobileNumber;
				staffHomeAddress = staff.homeAddress;
				depName = CodeModelUtil.getWqDepInfoNameByStaffId(staffId);
			}
			this.reportTime = planLocate.reportTime;
			this.speed = planLocate.speed;
			this.logit = planLocate.logit;
			this.lat = planLocate.lat;
			this.logitOffset = planLocate.logitOffset;
			this.latOffset = planLocate.latOffset;
			this.locDesc = planLocate.locDesc;
			this.angle = planLocate.angle;
			this.direction = planLocate.direction;
		}
		
		/**
		 * 获取地图图标名称
		 */ 
		public function getMapIconName():String{
			var iconName:String = "mapOffline";//脱岗
			if(this.staffState){
				if(this.staffState==OFF_SITE){//脱岗
					iconName = "mapOffline";
				}else if(this.staffState==ON_WORK_AREA){//工作区域内
					iconName = "mapOnwork";
				}else if(this.staffState==ON_PASSAGE){//在途中
					iconName = "mapOnway";
				}
			}
			return iconName;
		}
		
		/**
		 * 获取状态名称
		 */ 
		public function setStateName():void{
			staffStateName = OFF_SITE_NAME;//脱岗
			if(this.staffState){
				if(this.staffState==OFF_SITE){//脱岗
					staffStateName = OFF_SITE_NAME;
				}else if(this.staffState==ON_WORK_AREA){//工作区域内
					staffStateName = ON_WORK_AREA_NAME;
				}else if(this.staffState==ON_PASSAGE){//在途中
					staffStateName = ON_PASSAGE_NAME;
				}
			}
		}
		
		
		public function convertToPointModel():PointModel{
			var point:PointModel = new PointModel(logit,lat,staffId,null,locDesc);
			point.time = this.reportTime;
			point.offsetLat = this.latOffset;
			point.offsetLng = this.logitOffset;
			point.direction = this.direction;
			point.label = this.staffName;
			point.id = this.staffId;
			point.phone = this.staffMobileNumber;
			point.depName = this.depName;
			
			return point;
		}
	}
}